package cn.parus.dynamicRouter.listener;

import cn.parus.dynamicRouter.component.RefreshRouteLocator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * @Author: Axel
 * @Description: TODO 路由初始化
 **/
@Component
@Slf4j
public class StartingListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private RefreshRouteLocator refreshRouteLocator;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        log.info("监听Spring启动事件");
        /**
         * TODO 从数据库中调度数据，初始化路由
         */
        refreshRouteLocator.buildRoutes();
    }
}